'use strict';

import * as path from 'path';
import * as fs from 'fs';

// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';

import { Util } from './Util'

import { ModalCreater } from './module/modal/creater';
import { ComponentCreator } from './module/component/createor';

// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {

    // Use the console to output diagnostic information (console.log) and errors (console.error)
    // This line of code will only be executed once when your extension is activated
    // console.log('Congratulations, your extension "vscodeextensionbyxugege" is now active!');

    // The command has been defined in the package.json file
    // Now provide the implementation of the command with  registerCommand
    // The commandId parameter must match the command field in package.json
    let disposable = vscode.commands.registerCommand('extension.createModal', (args) => {
        // The code you place here will be executed every time your command is executed
        // console.log(args)
        // Display a message box to the user
        // vscode.window.showInformationMessage('Hello World!createModal...');
        // vscode.

        if (args['fsPath']) {
            //创建文件
            var stat = fs.lstatSync(args['fsPath']);
            if (!stat.isDirectory()) {
                return vscode.window.showInformationMessage('必须在文件夹上操作！！！');
            }
            //显示文本输入框 输入modal名称
            vscode.window.showInputBox({
                placeHolder: '输入Modal名称'
            }).then((e) => {
                new ModalCreater().create({ modalName: e, filePath: args.fsPath });
            });
        }
    });

    context.subscriptions.push(disposable);
    var command_cc = vscode.commands.registerCommand('extension.create.component', (args) => {
        if (args['fsPath']) {
            var stat = fs.lstatSync(args['fsPath']);
            if (!stat.isDirectory()) {
                return vscode.window.showInformationMessage('必须在文件夹上操作！！！');
            }
            vscode.window.showInputBox({
                placeHolder: '输入组件名称'
            }).then((e) => {
                new ComponentCreator().create({ componentName: e, filePath: args.fsPath });
            });
        }
    });
    context.subscriptions.push(command_cc);
}

// this method is called when your extension is deactivated
export function deactivate() {
}